package extreme.tddscaffold;

public class GoldInlaidRose {

    Commodity commodity;

    public GoldInlaidRose(Commodity commodity) {
        this.commodity = commodity;
    }

    public Commodity updateQuality() {
        return getCommodity();

    }

    private Commodity getCommodity() {
        //陈年干酪
        if (commodity.name.equals("Aged Brie")) {
            extracted();
        }
        //后台门票
        else if (commodity.name.equals("Backstage pass")) {
            extracted1();
        }
        //萨弗拉斯
        else if (commodity.name.equals("Sulfuras")) {
            extracted2(commodity.quantity);
        }
        //长剑
        else if (!commodity.name.equals("Sulfuras") && !commodity.name.equals("Sulfuras") && !commodity.name.equals("Sulfuras")) {
            extracted2();
        }
        return commodity;
    }

    private void extracted2() {
        if (commodity.sellIn >= 0) {
            commodity.quantity = commodity.quantity - 1;
            commodity.sellIn = commodity.sellIn - 1;
        } else {
            for (int i = commodity.sellIn; i < 0; i++) {
                commodity.sellIn = commodity.sellIn - 1;
                commodity.quantity = commodity.quantity - 2;
            }
        }
    }

    private void extracted2(int quantity) {
        commodity.quantity = quantity;
    }

    private void extracted1() {
        if (commodity.sellIn <= 0) {
            commodity.quantity = -1;
        } else if (commodity.sellIn > 0 && commodity.sellIn <= 5) {
            commodity.quantity = commodity.quantity + 2;
        } else if (commodity.sellIn > 5 && commodity.sellIn <= 10) {
            commodity.quantity = commodity.quantity + 1;
        } else if (commodity.quantity > 50) {
            commodity.quantity = 50;
        }
        commodity.sellIn = commodity.sellIn - 1;
        commodity.quantity = commodity.quantity + 1;
    }

    private void extracted() {
        commodity.sellIn = commodity.sellIn - 1;
        commodity.quantity = commodity.quantity + 1;
        if (commodity.sellIn < 0) {
            commodity.quantity = commodity.quantity + 1;
        }
        if (commodity.quantity > 50) {
            commodity.quantity = 50;
        }
    }
}